import useReportStore from '@/stores/useReportStore'
import { v4 as uuidv4 } from 'uuid'
import constants from "@/utils/constants";
import {uploadOssFile} from "@/api/ossFile.js";

//生成文件后上传到oss
export async function uploadReport(type, fileName, arrayBuffer) {
  let uuidFileName = uuidv4() + fileName
  //上传文件
  await uploadOssFile({
    fileName: uuidFileName,
    fileBuffer: arrayBuffer,
    type,
    user: constants.username
  })

  //更新store中的count
  useReportStore().report[type].push({
    fileName: uuidFileName,
    originName: fileName,
    path: `${constants.username}/${type}/${uuidFileName}`
  })

  //上传count.json
  await uploadOssFile({
    fileName: 'count.json',
    fileBuffer: JSON.stringify(useReportStore().report),
    user: constants.username,
    type: 'count'
  })
}
